// 环境变量使用vite的静态替换，统一在此管理。务必不要在别处使用 import.meta.env
import * as R from "ramda"
import {appEnv, EnvValueType, AppEnvKey} from "@/conf/env"

export function useEnv(keys : AppEnvKey[]): EnvValueType[] {
  return R.props(keys, appEnv)
}

export function isIcon(value: unknown): boolean {
  return typeof value === 'string'
    && value.startsWith('http')
    && R.any((ext) => value.endsWith(ext), ['.svg', '.ico'])
}

export function isNumber(value: unknown): boolean {
  switch (typeof value) {
    case 'number': return true
    case 'string':
      return /^\d+$/.test(value.trim())
  }
  return false
}
